package cn.dsttl3.tupan.slice;

import cn.dsttl3.tupan.MyApp;
import cn.dsttl3.tupan.ResourceTable;
import cn.dsttl3.tupan.utils.DataUtils;
import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;
import ohos.aafwk.content.Operation;
import ohos.data.preferences.Preferences;

public class MainAbilitySlice extends AbilitySlice {
    @Override
    public void onStart(Intent intent) {
        super.onStart(intent);
        super.setUIContent(ResourceTable.Layout_ability_main);
        Preferences preferences = new DataUtils().getPreferences(getApplicationContext());
        String token = preferences.getString("token",null);
        // 未登录状态，跳转至登录界面
        if (token == null){
            Intent intent1 = new Intent();
            Operation operation = new Intent.OperationBuilder()
                    .withBundleName(MyApp.bundleName)
                    .withAbilityName("cn.dsttl3.tupan.Ability.LoginAbility")
                    .build();
            intent1.setOperation(operation);
            startAbility(intent1);
            terminateAbility();
        // 已登录状态，跳转至首页
        }else {
            Intent intent1 = new Intent();
            Operation operation = new Intent.OperationBuilder()
                    .withBundleName(MyApp.bundleName)
                    .withAbilityName("cn.dsttl3.tupan.Ability.IndexAbility")
                    .build();
            intent1.setOperation(operation);
            startAbility(intent1);
            terminateAbility();
        }
    }

    @Override
    public void onActive() {
        super.onActive();
    }

    @Override
    public void onForeground(Intent intent) {
        super.onForeground(intent);
    }
}
